package pl.matt.media.extractor.impl;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import pl.matt.media.extractor.AbstractExtractor;
import pl.matt.media.manager.MediaManagersFactory;
import pl.matt.model.Rectangle;

/**
 * @deprecated
 * @author mateusz
 * 
 */

public class NoseExtractor extends AbstractExtractor {

	@SuppressWarnings("unused")
	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NoseExtractor.class);
	
	private File mainDir;
	private List<File> files;
	private String noseRegionSuffix;
	private String noseSuffix;
	
	public NoseExtractor(File mainDir, String noseRegionSuffix, String noseSuffix) {
		this.mainDir = mainDir;
		this.noseRegionSuffix = noseRegionSuffix;
		this.noseSuffix = noseSuffix;
	}
	
	@Override
	protected Collection<Rectangle> extract(File file) {
		return MediaManagersFactory.getObjectsDetectorManager().detectNoses(file.getAbsolutePath());
	}

	@Override
	protected List<File> getFiles() {
		if (files == null) {
			files = new ArrayList<File>();
			File[] dirs = mainDir.listFiles();
			List<File> dirList = Arrays.asList(dirs);
			Collections.sort(dirList);			
			for (File dir : dirList) {
				if (dir.isDirectory()) {
					File[] eyes = dir.listFiles(new FilenameFilter() {
						
						@Override
						public boolean accept(File dir, String name) {
							return name.contains(noseRegionSuffix);
						}
					});
					files.add(eyes[0]);					
				}
			}
		}
		return files;
	}

	@Override
	protected File getResultFile(File inputFile, int imageIndex) {
		String path = inputFile.getAbsolutePath();
		path = path.replace(noseRegionSuffix, noseSuffix);
		return new File(path);
	}
	
}